package org.lql.algo.codecrush.week001;

/**
 * @author: liangqinglong
 * @date: 2025-07-23 17:02
 * @description: LCR 182. 动态口令 <a href="https://leetcode.cn/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/description/">...</a>
 **/
public class DynamicPassword {

	/**
	 * 某公司门禁密码使用动态口令技术。初始密码为字符串 password，密码更新均遵循以下步骤：
	 * <p>
	 * 设定一个正整数目标值 target
	 * 将 password 前 target 个字符按原顺序移动至字符串末尾
	 * 请返回更新后的密码字符串。
	 * <p>
	 * 示例 1：
	 * <p>
	 * 输入: password = "s3cur1tyC0d3", target = 4
	 * 输出: "r1tyC0d3s3cu"
	 * 示例 2：
	 * <p>
	 * 输入: password = "lrloseumgh", target = 6
	 * 输出: "umghlrlose"
	 */
	public String dynamicPassword(String password, int target) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < password.length(); i++) {
			if (i >= target) {
				sb.append(password.charAt(i));
			}
		}
		for (int i = 0; i < target; i++) {
			sb.append(password.charAt(i));
		}
		return sb.toString();
	}

	public static void main(String[] args) {
		DynamicPassword dynamicPassword = new DynamicPassword();
		System.out.println(dynamicPassword.dynamicPassword("s3cur1tyC0d3", 4));
	}
}
